package com.ysd.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ysd.qxgl.dao.IRoleUserDao;
import com.ysd.qxgl.model.Roles;
import com.ysd.qxgl.service.IRoleUserService;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/roleuser")
public class RoleUserController {

    @Resource
    private IRoleUserDao roleUserDao;
    @Resource
    private IRoleUserService roleUserService;

    @ApiOperation(value = "根据用户编号查询角色",notes = "根据用户编号查询角色")
    @ApiImplicitParam(name = "user_id",value = "用户编号",required = true,paramType = "path")
    @PostMapping("/findRolesBuUserId/{user_id}")
    public Map<String,Object> findRolesBuUserId(@PathVariable String user_id){
        List<Roles> list = roleUserDao.findRolesByUserId(user_id);
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "设置用户角色",notes = "设置用户角色")
    @PostMapping("/setUserRoles") 
    public void setUserRoles(String user_id,@RequestParam List<String> role_id){
        roleUserService.setUserRoles(user_id, role_id);
    } 
}